package leetcode.code0671;

import leetcode.IDebug;
import leetcode.helper.tree.TreeNode;

public class Solution implements IDebug {

	Integer ans;
	int min;

	public int findSecondMinimumValue(TreeNode root) {
		ans = null;
		min = root.val;
		this.secondMinimumValue(root);
		return ans == null ? -1 : ans;
	}

	private void secondMinimumValue(TreeNode root) {
		if (root == null) {
			return;
		}
		if (ans == null) {
			if (root.val > min) {
				ans = root.val;
			}
		} else {
			if (root.val > min && root.val < ans) {
				ans = root.val;
			}
		}
		this.secondMinimumValue(root.left);
		this.secondMinimumValue(root.right);
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
